home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ian & Stuart's Australian Mac 1993 September
/
clonecd
/
September 93.img
/
Archives
/
Utilities
/
Quicktime
/
SLINK's VCR QuickTime
/
MP Source
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-06-15
|
11KB
|
537 lines
/*---------------------------------------------------------------------
File: main.c
Purpose:
Created by: Geoffrey Slinker
Date: 8:26:41 AM 6/8/92
Modified:
---------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <oops.h>
#include <Movies.h>
#include "Dlog.h"
#include "about_Dlog.h"
#include "Alert_Class.h"
#include "vcr.h"
#include "mycolors.h"
#include "myQuickTime.h"
#define NUKE_ALL_EVENTS 0
#define NULL_POINTER NULL
#define MY_ALERT 601
//#define VCR_DLOG 700
#define VCR_DLOG 702
#define BASE_MENU 600
#define APPLE_ID 600
#define FILE_ID 601
#define ABOUT_ITEM 1
#define OPEN_ITEM 1
#define CLOSE_ITEM 2
#define QUIT_ITEM 4
/*-------------------------
protos
-------------------------*/
void InitMac(void);
void MainLoop(void);
int Eventful(void);
int HandleMouseDown(void);
int HandleMenuChoice (long int choice);
void HandleAppleChoice(int theItem);
int HandleFileChoice(int theItem);
void MenuBarInit(void);
void InitMyStuff(void);
void CleanUpMyStuff(void);
void ClockTask(void);
void MaintainMenus(void);
/*-------------------------
globals
-------------------------*/
EventRecord gEvent;
MenuHandle gAppleMenu;
about_Dlog *aboutDlog;
Alert_Class *myAlert;
QT *myQT;
Boolean moviesLoaded = false;
VCR *vcr;
Boolean opened = false;
//DateTimeRec oldT;
long oldClockTick; // used for updating vcr clock
extern Boolean blink;
extern long oldTick; // used for updating status
/**********************************************************************/
void main()
{
InitMac();
InitMyStuff();
(*myQT).MovieCheck(); // Is QuickTime available?
moviesLoaded = true;
MainLoop();
CleanUpMyStuff();
}
/*---------------------------------------------------------------------
Function: InitMac()
Purpose:
Returns:
Created by: Geoffrey Slinker
Date: 8:30:00 AM 6/8/92
Modified:
---------------------------------------------------------------------*/
void InitMac()
{
InitGraf(&thePort);
InitFonts();
FlushEvents(everyEvent,NUKE_ALL_EVENTS);
InitWindows(); // This calls InitPalettes
InitMenus();
TEInit();
InitDialogs(NULL_POINTER);
InitCursor();
MaxApplZone();
/*-------------------------
Other things related to the MAC
or the MAC interface that needs
to be initiated
-------------------------*/
MenuBarInit();
}
/*---------------------------------------------------------------------
Function: void MainLoop()
Purpose: repeatedly call function with getnext event and very
large switch statement.
Returns:
Created by: Geoffrey Slinker
Date: 8:33:44 AM 6/8/92
Modified:
---------------------------------------------------------------------*/
void MainLoop()
{
AppFile theFile;
int message, count;
int response = 1;
/*-------------------------
Was the application launched
by double click on a file
of our type?
Since this application does
not save QT files, this will
never happen.
-------------------------*/
CountAppFiles(&message,&count);
if ( (message == 0) && (count >= 1) ) {
GetAppFiles(1,&theFile);
ClrAppFiles(1);
} /* end if */
while (response == 1){
response = Eventful();
}
}
/*---------------------------------------------------------------------
Function: Eventful()
Purpose: Contains GetNextEvent and the switch statement.
Returns:
Created by: Geoffrey Slinker
Date: 8:35:17 AM 6/8/92
Modified:
---------------------------------------------------------------------*/
int Eventful()
{
int response = 1;
char theChar;
GrafPtr aPort;
WindowPtr whichWindow;
Movie myMovie;
CWindowPtr movieWindow;
myMovie = (*myQT).myMovie;
movieWindow = (*myQT).movieWindow;
SystemTask();
ClockTask();
(*myQT).MyMoviesTask();
GetNextEvent(everyEvent,&gEvent);
switch ( gEvent.what ) {
case mouseDown:
response = HandleMouseDown();
break;
case keyDown:
case autoKey:
theChar = gEvent.message & charCodeMask;
if ( (gEvent.modifiers & cmdKey) != 0 ) {
response = HandleMenuChoice( MenuKey(theChar));
}
else {
whichWindow = FrontWindow();
}
break;
case activateEvt:
SetPort( (WindowPtr) gEvent.message );
InvalRect(&((WindowPtr)gEvent.message)->portRect);
break;
case updateEvt:
{
Boolean isDaWindow;
if ( whichWindow == NULL_POINTER ) {
isDaWindow = false;
}
else {
isDaWindow = (( (WindowPeek)whichWindow)->windowKind < 0);
} /* end if then else */
if ( !isDaWindow )
{
BeginUpdate((WindowPtr)gEvent.message);
GetPort(&aPort);
SetPort((WindowPtr)gEvent.message);
if ( (WindowPtr)gEvent.message == (*vcr).myDlog) {
(*vcr).RedrawDialog();
}
if ((CWindowPtr)gEvent.message == movieWindow) {
UpdateMovie( myMovie );
}
if ((CWindowPtr)gEvent.message == (*myQT).moviePosterWindow) {
(*myQT).RedrawPoster();
}
EndUpdate((WindowPtr)gEvent.message);
SetPort(aPort);
} /* end if */
}
break;
case nullEvent:
MaintainMenus();
break;
default:
response = 1;
break;
} /* end switch */
return(response);
}
/*---------------------------------------------------------------------
Function: HandleMouseDown
Purpose:
Returns:
Created by: Geoffrey Slinker
Date: 8:38:43 AM 6/8/92
Modified:
---------------------------------------------------------------------*/
int HandleMouseDown()
{
WindowPtr whichWindow,frontWindow;
short int thePart;
long int menuChoice, windSize;
Rect bRect;
int response = 1;
Point thePoint;
thePart = FindWindow(gEvent.where,&whichWindow);
switch ( thePart ) {
case inMenuBar:
menuChoice = MenuSelect(gEvent.where);
response = HandleMenuChoice(menuChoice);
break;
case inSysWindow:
SystemClick(&gEvent,whichWindow);
break;
case inDrag:
SelectWindow(whichWindow);
bRect = screenBits.bounds;
DragWindow(whichWindow,gEvent.where, &bRect);
break;
case inContent:
frontWindow = FrontWindow();
SelectWindow(whichWindow);
SetPort(whichWindow);
if (whichWindow == (*vcr).myDlog) {
(*vcr).HandleDialog(&gEvent);
}
break;
case inGoAway:
HideWindow(whichWindow);
break;
default: response = 1; break;
} /* end switch */
return(response);
}
/*---------------------------------------------------------------------
Function: int HandleMenuChoice(long int choice)
Purpose: Distribute the menu choice to the proper handler.
Returns:
Created by: Geoffrey Slinker
Date: 8:41:11 AM 6/8/92
Modified:
---------------------------------------------------------------------*/
int HandleMenuChoice (long int choice)
{
int theMenu;
int theItem;
int response;
char stuff[80];
Str255 message;
response = 1;
if (choice != 0) {
theMenu = HiWord(choice);
theItem = LoWord(choice);
switch ( theMenu ) {
case APPLE_ID:
HandleAppleChoice(theItem);
break;
case FILE_ID:
response = HandleFileChoice(theItem);
break;
default:
sprintf((char *)message,"Menu Bar Item = %d",theItem);
(*myAlert).AlertCaution("\pUnimplemented Menu Bar Item",
CtoPstr(message),"\pSorry!",NULL);
break;
} /* end switch */
} /* end if */
HiliteMenu(0);
return(response);
}
/*---------------------------------------------------------------------
Function: HandleAppleChoice
Purpose:
Returns:
Created by: Geoffrey Slinker
Date: 8:42:38 AM 6/8/92
Modified:
---------------------------------------------------------------------*/
void HandleAppleChoice(int theItem)
{
Str255 accName;
int accNumber;
switch ( theItem ) {
case ABOUT_ITEM:
(*aboutDlog).HandleDialog(&gEvent);
break;
default:
GetItem(gAppleMenu,theItem,accName);
accNumber = OpenDeskAcc(accName);
break;
} /* end switch */
}
/*---------------------------------------------------------------------
Function: HandleFileChoice
Purpose:
Returns:
Created by: Geoffrey Slinker
Date: 8:44:06 AM 6/8/92
Modified:
---------------------------------------------------------------------*/
int HandleFileChoice(int theItem)
{
int response;
WindowPtr whichWindow;
Str255 message;
response = 1;
switch ( theItem ) {
case OPEN_ITEM:
opened = (*myQT).OpenMovie();
break;
case CLOSE_ITEM:
(*myQT).CloseMovie();
opened = false;
break;
case QUIT_ITEM: response = 0; break;
default:
sprintf((char *)message,"Menu Bar Item = %d",theItem);
(*myAlert).AlertCaution("\pUnimplemented Menu Bar Item",
CtoPstr(message),"\pSorry!",NULL);
break;
} /* end switch */
return(response);
}
/*---------------------------------------------------------------------
Function: void MenuBarInit()
Purpose: Load the menu resources
Returns:
Created by: Geoffrey Slinker
Date: 9:06:34 AM 6/8/92
Modified:
---------------------------------------------------------------------*/
void MenuBarInit()
{
Handle myBar;
if ( (myBar = GetNewMBar(BASE_MENU)) == NULL_POINTER ) {
ExitToShell();
} /* end if */
SetMenuBar(myBar);
if ( (gAppleMenu = GetMHandle( APPLE_ID)) == NULL_POINTER ) {
ExitToShell();
} /* end if */
AddResMenu(gAppleMenu,'DRVR');
DrawMenuBar();
}
/*---------------------------------------------------------------------
Function: InitMyStuff();
Purpose:
Returns:
Created by: Geoffrey Slinker
Date: 9:16:28 AM 6/8/92
Modified:
---------------------------------------------------------------------*/
void InitMyStuff()
{
DialogPtr myDlog;
//GetTime(&oldT);
oldClockTick = oldTick = TickCount();
//oldTick = TickCount();
aboutDlog = new about_Dlog;
(*aboutDlog).loadResource(ABOUT_DLOG);
myAlert = new Alert_Class;
(*myAlert).ChooseResource(MY_ALERT);
vcr = new VCR;
(*vcr).loadResource(VCR_DLOG);
(*vcr).PutUpDialog();
myQT = new QT;
(*myQT).LoadResources();
}
/*---------------------------------------------------------------------
Function: CleanUpMyStuff()
Purpose:
Returns:
Created by: Geoffrey Slinker
Date: 9:16:28 AM 6/8/92
Modified:
---------------------------------------------------------------------*/
void CleanUpMyStuff()
{
delete aboutDlog;
delete myAlert;
delete vcr;
delete myQT;
if (moviesLoaded) {
ExitMovies();
}
}
/*---------------------------------------------------------------------
Function: ClockTask();
Purpose:
Returns:
Created by: Geoffrey Slinker
Date: 4:22:18 PM 6/12/92
Modified:
---------------------------------------------------------------------*/
void ClockTask()
{
long newClockTick;
Boolean blinky;
blinky = blink;
newClockTick = TickCount();
if ( (newClockTick - oldClockTick) >= 60) {
blink = !blink;
oldClockTick = newClockTick;
}
if (blink != blinky) (*vcr).RedrawTime();
(*vcr).UpdateProgress();
}
/*---------------------------------------------------------------------
Function: void MaintainMenus()
Purpose:
Returns:
Created by: Geoffrey Slinker
Date: 10:49:56 AM 6/13/92
Modified:
---------------------------------------------------------------------*/
void MaintainMenus()
{
WindowPtr frontWindow;
MenuHandle theMenu;
DialogPtr myDlog;
theMenu = GetMHandle(FILE_ID);
if (opened) {
DisableItem(theMenu,OPEN_ITEM);
EnableItem(theMenu,CLOSE_ITEM);
}
else {
DisableItem(theMenu,CLOSE_ITEM);
EnableItem(theMenu,OPEN_ITEM);
}
}